﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QunYing.Web.market
{
    public partial class water : System.Web.UI.Page
    {
        protected void Page_LoadComplete(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater rp = ((Repeater)Master.FindControl("NavRepeater"));
                rp.DataSource = NavData();
                rp.DataBind();
            }
        }
        /// <summary>
        /// 快捷导航数据
        /// </summary>
        private DataTable NavData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            dt.Columns.Add("url");
            dt.Rows.Add("水族环境", "");
            return dt;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlBind();
                BindInfo();
            }
        }
        /// <summary>
        /// 绑定下拉框
        /// </summary>
        private void ddlBind()
        {
            string userName = ((ArrayList)Session["userInfo"])[0].ToString();
            BLL.DeviceInfo info = new BLL.DeviceInfo();
            DataTable dt = info.QueryDevice(userName);
            ddlDevice.DataSource = dt;
            ddlDevice.DataTextField = "名称";
            ddlDevice.DataValueField = "ICSA编号";
            ddlDevice.DataBind();
        }

        /// <summary>
        /// 绑定信息
        /// </summary>
        private void BindInfo()
        {
            string strIcsa = string.Empty;
            string strTime = string.Empty;
            if (Session["icsa"] != null)
            {
                strIcsa = Session["icsa"].ToString();
                ddlDevice.SelectedValue = strIcsa;
                Session.Remove("icsa");
            }
            if (Session["time"] != null)
            {
                strTime = Session["time"].ToString();
                Session.Remove("time");
            }
            //if (string.IsNullOrEmpty(strIcsa))
            //{
            //    strIcsa = ddlDevice.SelectedValue;
            //}
            BLL.DeviceRealTimeInfo info = new BLL.DeviceRealTimeInfo();
            Model.DeviceRealTimeInfo model = info.GetModel(ddlDevice.SelectedValue, strTime);
            if (model == null)
            {
                clearText();
                return;
            }
            lblTime.Text = model.数据接收时间.ToString("yyyy-MM-dd HH:mm");
            lblTingDian.Text = convertBool(model.停电告警);
            lblShuiWei.Text = convertBool(model.水位告警);
            lblShuiWen.Text = convertBool(model.水温告警);
            lblXunHuan.Text = convertBool(model.水循环告警);
            lblPH.Text = convertBool(model.PH告警);
            lblORP.Text = convertBool(model.ORP告警);
           // lblWenKong.Text = convertBool(model.温控设备告警);
            lblORP.Text = convertBool(model.ORP告警);
            lblYang.Text = convertBool(model.氧循环告警);
            //lblGai.Text = convertBool(model.钙反应器告警);
           // lblFanXiao.Text = convertBool(model.反硝器告警);
           // lblDianChi.Text = convertBool(model.蓄电池告警);
            lblChuanGan.Text = convertBool(model.传感器告警);
            lblWenDu.Text = model.水族箱温度值.ToString();
            lblORPValue.Text = model.水族箱ORP值.ToString();
            lblPHValue.Text = model.水族箱PH值.ToString();
           // lblGaiPH.Text = model.钙反应器PH值.ToString();
            lblDY.Text = model.蓄电池电压.ToString();
            HighTexts();
        }

        private string convertBool(bool b)
        {
            if (b)
            {
                return "有";
            }
            else
            {
                return "无";
            }
        }

        private void clearText()
        {
            lblTime.Text = "没有告警信息!";
            lblTingDian.Text = string.Empty;
            lblShuiWei.Text = string.Empty;
            lblShuiWen.Text = string.Empty;
            lblXunHuan.Text = string.Empty;
            lblPH.Text = string.Empty;
            lblORP.Text = string.Empty;
           // lblWenKong.Text = string.Empty;
            lblORP.Text = string.Empty;
            lblYang.Text = string.Empty;
            //lblGai.Text = string.Empty;
           // lblFanXiao.Text = string.Empty;
           // lblDianChi.Text = string.Empty;
            lblChuanGan.Text = string.Empty;
            lblWenDu.Text = string.Empty;
            lblORPValue.Text = string.Empty;
            lblPHValue.Text = string.Empty;
            //lblGaiPH.Text = string.Empty;
            lblDY.Text = string.Empty;
        }

        /// <summary>
        /// 高亮字体
        /// </summary>
        private void HighText(Label label)
        {
            if (label.Text == "有")
            {
                label.ForeColor = Color.Red;
            }
            else
            {
                label.ForeColor =Color.Black;//Color.FromArgb(0x0c1e76);
            }
        }

        private void HighTexts()
        {
            HighText(lblTingDian);
            HighText(lblShuiWei);
            HighText(lblShuiWen);
            HighText(lblXunHuan);
            HighText(lblPH);
            HighText(lblORP);
           // HighText(lblWenKong);
            HighText(lblORP);
            HighText(lblYang);
           // HighText(lblGai);
           // HighText(lblFanXiao);
           // HighText(lblDianChi);
            HighText(lblChuanGan);
            HighText(lblDY);
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindInfo();
        }
    }
}
